<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //先建立权限表
        $permission = [
            ['name'=>'write.index', 'cn_name'=>'文章列表',],
            ['name'=>'write.show', 'cn_name'=>'文章详情',],
            ['name'=>'write.store', 'cn_name'=>'文章发表',],
            ['name'=>'write.lock', 'cn_name'=>'文章删除',],
            ['name'=>'write.update', 'cn_name'=>'文章修改',],
            ['name'=>'write.col', 'cn_name'=>'文章收藏',],

            ['name'=>'comments.index', 'cn_name'=>'获得评论',],
            ['name'=>'comments.report', 'cn_name'=>'评论举报',],
            ['name'=>'comments.store', 'cn_name'=>'评论发表',],
            ['name'=>'comments.del', 'cn_name'=>'评论删除',],

            ['name'=>'user.feedback', 'cn_name'=>'用户意见反馈',],
            ['name'=>'user.infochange', 'cn_name'=>'用户信息修改',],
            ['name'=>'user.avatarchange', 'cn_name'=>'用户头像修改',],


        ];
//        foreach ($permissions as $p){
//            Permission::create($p);
//        }

        foreach ($permission as $p){
        Permission::create($p);
    }
        $role = Role::create(['name'=>'user','cn_name'=>'用户']);
//        $role->givePermissionTo();
        $role->givePermissionTo(Permission::all());



    }
}
